package com.updesignsz.admin.mapper;

import com.updesignsz.admin.vo.form.TypeForm;
import com.updesignsz.commom.entity.Type;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 项目类型
 * Creation date 2020-8-8 17:53:48
 */
@Repository
@Mapper
public interface TypeMapper {


    @Select({"<script>",
            "select * from type ",
            "<where>",
            "<if test=\"type != null\" >AND type = #{type}</if>",
            "</where>",
            "order by created_date desc",
            "</script>"
    })
    List<Type> listAll(Type type);


    @Select("select * from type where id = #{id}")
    Type getById(@Param("id") Integer id);

    @Insert({
            "insert into type(name, `type`, created_date, updated_date) ",
            "values (#{name},#{type},NOW(),NOW())"
    })
    @Options(useGeneratedKeys = true, keyColumn = "id")
    void saveType(TypeForm type);


    @Update({"<script>",
            "update type <set>",
            "<if test=\"name != null\" >name = #{name},</if>",
            "updated_date = NOW()",
            "</set> where id = #{id}",
            "</script>"
    })
    void updateType(TypeForm type);

    @Delete("delete from type where id = #{id}")
    void deleteType(@Param("id") Integer id);
}